package com.hsylient.resource.controller;

import com.hsylient.resource.config.ConfigFromAnnotation;
import com.hsylient.resource.config.ConfigFromBindingEntity;
import jakarta.annotation.Resource;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ResourceController {

    @Resource
    Environment configFromEnvironment;
    @Resource
    private ConfigFromAnnotation configFromAnnotation;
    @Resource
    private ConfigFromBindingEntity configFromBindingEntity;

    /**
     * 通过Environment读取配置中的信息
     */
    @GetMapping("/v3/config/from/env")
    public String configFromEnvironment() {
        return configFromEnvironment.getProperty("name");
    }

    /**
     * 通过注解获取
     */
    @GetMapping("/v3/config/from/value/annotation")
    public String configFromAnnotation() {
        return configFromAnnotation.getDescription();
    }


    /**
     * 绑定实体类
     * @return
     */
    @GetMapping("/v3/config/from/binding/entity")
    public String getConfigFrom() {
        return configFromBindingEntity.getUsername();
    }
}
